package com.teufandsub.socialproximity.gui;

import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.Toast;

import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.teufandsub.socialproximity.R;
import com.teufandsub.socialproximity.controller.Constants;
import com.teufandsub.socialproximity.controller.Controller;
import com.teufandsub.socialproximity.services.HttpService;
import com.teufandsub.socialproximity.services.LocationService;

public class HomeActivity extends SherlockActivity implements OnClickListener {
	
	/* Home activity, where you'll select what you want to do with our application :
	 *  - Find new friend
	 *  - Change your settings
	 *  ... */
	
	private Controller controller;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.activity_home);
		
		controller = Controller.getInstance();
		ImageButton bt_find_friend = (ImageButton) findViewById(R.id.button_find_friend);
		bt_find_friend.setOnClickListener(this);
		
		ImageButton bt_friend_list = (ImageButton) findViewById(R.id.button_friend_list);
		bt_friend_list.setOnClickListener(this);
		
		ImageButton bt_event_chat = (ImageButton) findViewById(R.id.button_event_chat);
		bt_event_chat.setOnClickListener(this);
		
		ImageButton bt_profil = (ImageButton) findViewById(R.id.button_profil);
		bt_profil.setOnClickListener(this);
	}
	
	public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
		MenuInflater inflater = this.getSupportMenuInflater();
		inflater.inflate(R.menu.home_menu, menu);
		return true;
	};
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		Intent intent;
		switch(item.getItemId()){
			case R.id.action_close:
				intent = new Intent(this, CloseActivity.class);
				startActivity(intent);
				break;
			case R.id.action_close_button:
				intent = new Intent(this, CloseActivity.class);
				startActivity(intent);
				break;
			case R.id.action_log_out: 
				controller.disconnect(this);
				break;
			default:;
		}
		return true;
	}
	
	@Override
	public void onClick(View v) {
		Intent i;
		switch(v.getId()){
			case R.id.button_find_friend:
				i = new Intent(this, ResearchFriendActivity.class);
				startActivity(i);
				break;
				
			case R.id.button_friend_list:
				i = new Intent(this, FriendListActivity.class);
				startActivity(i);
				break;
				
			case R.id.button_event_chat:
				Toast.makeText(HomeActivity.this, getResources().getString(R.string.comingsoon), Toast.LENGTH_SHORT).show();
				break;
				
			case R.id.button_profil:
				Toast.makeText(HomeActivity.this, getResources().getString(R.string.comingsoon), Toast.LENGTH_SHORT).show();
				break;
				
			default: Log.e(Constants.APP_NAME, "No action on this view");
		}	
	}
	
	@Override
	public void onBackPressed() {
		controller.checkSession(this, HomeActivity.class);
	}
}
